home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / xlib04.zip / XMOUSE.ASM < prev    next >
Assembly Source File  |  1992-11-12  |  23KB  |  801 lines

  1. ;-----------------------------------------------------------------------
  2. ; MODULE XMOUSE
  3. ;
  4. ; Mouse functions functions for all MODE X 256 Color resolutions
  5. ;
  6. ; Compile with Tasm.
  7. ; C callable.
  8. ;
  9. ; ****** XLIB - Mode X graphics library                ****************
  10. ; ******                                               ****************
  11. ; ****** Written By Themie Gouthas                     ****************
  12. ;
  13. ; This module is based on Shane Hyde's module of the same name,
  14. ; posted to Rec.Games.Programmer, October 92.
  15. ;
  16. ; egg@dstos3.dsto.gov.au
  17. ; teg@bart.dsto.gov.au
  18. ;-----------------------------------------------------------------------
  19.  
  20. COMMENT  $
  21.  
  22.  
  23. This is a module implementing very basic mouse functions.
  24.  
  25. It does not support the full functionality of:
  26.  
  27.   SPLIT SCREENS
  28.   SCROLLED WINDOWS
  29.   VIRTUAL WINDOWS
  30.  
  31.           --------------------------------------
  32.  
  33.           MS Mouse Driver Functions
  34.  
  35.           Mouse Initialization                 0
  36.           Show Cursor                          1
  37.           Hide Cursor                          2
  38.           Get Mouse Position & Button Status   3
  39.           Set Mouse Cursor Position            4
  40.           Get Button Press Information         5
  41.           Get Button Release Information       6
  42.           Set Min/Max Horizontal Position      7
  43.           Set Min/Max Vertical Position        8
  44.           Define Graphics Cursor Block         9
  45.           Define Text Cursor                  10
  46.           Read Mouse Motion Counters          11
  47.           Define Event Handler                12
  48.           Light Pen Emulation Mode ON         13
  49.           Light Pen Emulation Mode OFF        14
  50.           Set Mouse Mickey/Pixel Ratio        15
  51.           Conditional Hide Cursor             16
  52.           Set Double-Speed Threshold          19
  53.           --------------------------------------
  54. $
  55.  
  56. include xlib.inc
  57. include xdetect.inc
  58.  
  59. .data
  60.  
  61. global   _MouseInstalled    :word
  62. global   _MouseHidden       :word
  63. global   _MouseButtonStatus :word
  64. global   _MouseX            :word
  65. global   _MouseY            :word
  66. global   _MouseFrozen       :byte
  67. global   _MouseColor        :byte
  68.  
  69. global   _x_define_mouse_cursor :proc
  70. global   _x_show_mouse          :proc
  71. global   _x_hide_mouse          :proc
  72. global   _x_mouse_remove        :proc
  73. global   _x_position_mouse      :proc
  74. global   _x_put_cursor          :proc
  75. global   _x_update_mouse        :proc
  76. global   _x_mouse_init          :proc
  77.  
  78.  
  79. ALIGN 2
  80.    InitMouseDef db 00000001b  ; Default mouse mask, note the reverse order
  81.         db 00000011b
  82.         db 00000111b
  83.         db 00001111b
  84.         db 00011111b
  85.         db 00111111b
  86.         db 01111111b
  87.         db 11111111b
  88.         db 00011100b
  89.         db 00111100b
  90.         db 01111100b
  91.         db 00000000b
  92.         db 00000000b
  93.         db 00000000b
  94.  
  95.     MouseMask          db 168 dup(?)
  96.     OldHandlerSeg      dw  ?
  97.     OldHandlerOffs     dw  ?
  98.     OldHandlerMask     dw  ?
  99.     OldX               dw  ?
  100.     OldY               dw  ?
  101.     OldScrnOffs        dw  ?
  102.  
  103.     BGSaveOffs         dw  0
  104.  
  105.    _MouseInstalled     dw 0     ; Flag indicating whether mouse is installed
  106.    _MouseHidden        dw 0     ; Flag indicating whether mouse is hidden
  107.    _MouseButtonStatus  dw 0     ; Holds current button press information
  108.    _MouseX             dw 0     ; Coords of cursor hot spot
  109.    _MouseY             dw 0
  110.    _MouseFrozen        db 0     ; Mouse motion enable/disable control
  111.    _MouseColor         db 0     ; Mouse cursor colour
  112.  
  113.    inhandler           db 0
  114. .code
  115.  
  116.  
  117. ;----------------------------------------------------------------------
  118. ; x_mouse_init - Initialise Mode X mouse handler
  119. ;
  120. ; C Prototype
  121. ;
  122. ;  int x_mouse_init()
  123. ;
  124. ; This is the first function you must call before using any of the mouse
  125. ; functions
  126. ;
  127. ; WARNING: This function uses and updates "NonVisual_Offset" to allocate
  128. ;          video ram for the saved mouse background.
  129. ;
  130. ; This mouse code uses the fastest possible techniques to save and restore
  131. ; mouse backgrounds and to draw the mouse cursor.
  132. ;
  133. ; LIMITATIONS: No clipping is supported horizontally for the mouse cursor
  134. ;              No validity checking is performed for NonVisual_Offs
  135. ;
  136. ;
  137. ; **WARNING** Hide or freeze mouse while drawing using any of the other
  138. ;             Modules. VGA register settings are not preserved which will
  139. ;             result in unpredictable drawing behavior.
  140. ;             If you know the drawing will occur away from the mouse cursor
  141. ;             set MouseFrozen to TRUE (1), do your drawing then set it to
  142. ;             FALSE (0). Alternatively call "x_hide_mouse", perform your
  143. ;             drawing and then call "x_show_mouse"
  144. ;
  145. ;
  146. ; Written by Themie Gouthas
  147. ;----------------------------------------------------------------------
  148. _x_mouse_init proc
  149.      push  bp
  150.      mov   bp,sp
  151.  
  152.      cmp   [_MouseButtonCount],0  ; Dont initialize if mouse detection
  153.      jne   @@DontInitialize       ; or initialization function previously
  154.                   ;   called
  155.      xor   ax,ax                  ; FUNC 0: Mouse Initialization
  156.      int   33h                    ;
  157.      or    ax,ax                  ; Is there a mouse installed ?
  158.      jz    @@Done
  159.      mov   [_MouseButtonCount],bx ; Set the button count
  160.  
  161. @@DontInitialize:
  162.  
  163.      mov   [_MouseInstalled],ax
  164.      or    ax,ax                  ; Do we have an installed mouse driver ?
  165.      jz    @@Done                 ; Nop!
  166.  
  167.      mov   ax,[_NonVisual_Offs];  ; Allocate VRAM for saved background
  168.      mov   BGSaveOffs,ax
  169.  
  170.      add   ax,14*3
  171.      mov   [_NonVisual_Offs],ax   ; Update NonVisualOffset
  172.  
  173.      mov   ax,02                  ; FUNC 2: Hide Cursor
  174.      int   33h                    ;  (hide the mouse driver's default cursor)
  175.      mov   _MouseInstalled,TRUE   ; Indicate user mouse driver present
  176.  
  177.      mov   ax,07h                 ; FUNC 7:Set min/max horizontal position
  178.      mov   cx,0
  179.      mov   dx,[_ScrnPhysicalPixelWidth]
  180.      shl   dx,1                   ; Mult X by 2 as cursor steps by 2 pixels
  181.      int   33h                    ; 0 < X < _ScrnPhysicalPixelWidth
  182.  
  183.      mov   ax,08h                 ; FUNC 8:Set min/max vertical position
  184.      mov   cx,0
  185.      mov   dx,_ScrnPhysicalHeight
  186.      int   33h                    ; 0 < Y < _ScrnPhysicalHeight
  187.  
  188.      mov   ax,0fh                 ; FUNC 15: Mouse Hor/Vert resolution
  189.      mov   cx,4                   ; Horiz speed  >> Value => << Speed
  190.      mov   dx,8                   ; Vert Speed
  191.      int   33h
  192.  
  193.      mov   ax,12                  ; FUNC 12: Define Event Handler
  194.      mov   bx,seg mouse_handler   ;  ES:DX -> Event handler
  195.      mov   es,bx
  196.      mov   dx,offset mouse_handler
  197.      mov   cx,1fh                 ;  Set handler for all events
  198.      int   33h
  199.  
  200.      mov   [_MouseHidden],TRUE    ; Mouse initially hidden
  201.  
  202.      push  ds                     ; Set the default cursor shape
  203.      mov   ax,offset InitMouseDef
  204.      push  ax
  205.      call  _x_define_mouse_cursor
  206.      add   sp,04h
  207.  
  208.      mov   ax,[_MouseInstalled]   ; Return MouseInstalled flag
  209. @@Done:
  210.      pop   bp
  211.      ret
  212. _x_mouse_init endp
  213.  
  214.  
  215. ;----------------------------------------------------------------------
  216. ; x_define_mouse_cursor - Define a mouse cursor from an input bitmask
  217. ;
  218. ; C Prototype
  219. ;
  220. ;  void x_define_mouse_cursor(char far *MouseDef, unsigned char MouseColor)
  221. ;
  222. ; WARNING: This function assumes MouseDef points to 14 bytes.
  223. ;
  224. ; Note: Bit order is in reverse. ie bit 7 represents pixel 0 ..
  225. ;       bit 0 represents pixel 7 in each "MouseDef" byte.
  226. ;
  227. ; Written by Themie Gouthas
  228. ;----------------------------------------------------------------------
  229. _x_define_mouse_cursor proc
  230. ARG MouseDef:dword,MouseColor:byte
  231.      push  bp
  232.      mov   bp,sp
  233.  
  234.      cmp  [_MouseInstalled],FALSE   ; Check whether we have installed
  235.      je   @@Done                    ;  our mouse handler and leave if not
  236.  
  237.      mov  al,[MouseColor]           ; Set the mouse pointers color
  238.      mov  [_MouseColor],al
  239.  
  240.      push  si
  241.      push  di
  242.      push  ds
  243.      mov   ax,ds                ; ES:DI -> Stored plane mask for all
  244.      mov   es,ax                ;   pixel alignments of mouse cursor
  245.      mov   di,offset MouseMask
  246.      lds   si,MouseDef
  247.      xor   cl,cl                ; CL = current alignment (initially zero)
  248. @@AlignmentLoop:
  249.      push  si                   ; save MouseDef ptr for next alignment
  250.      mov   dh,14                ; Init Row counter to Cursor Height
  251. @@RowLoop:
  252.      lodsb                      ; Load first cursor def byte each bit
  253.                 ;  representing pixel in the row
  254.      xor   ah,ah                ; AH is the shift overflow byte
  255.      shl   ax,cl                ; Shift mask for current alignment
  256.  
  257.      mov   bl,al                ; store first three nibbles of ax into
  258.      and   bl,0fh               ;  consecutive bytes in the destination
  259.      mov   es:[di],bl           ;  buffer
  260.      inc   di
  261.      shr   al,4
  262.      stosw
  263.  
  264.      dec   dh                   ; Next row for this alignment if there
  265.      jnz   @@RowLoop            ;  are more to do
  266.  
  267.      pop   si                   ; point to the start of the cursor def.
  268.      inc   cl                   ; Select next pixel alignment
  269.      cmp   cl,4                 ; If there are more alignments to do
  270.      jne   @@AlignmentLoop      ;   then jump
  271.  
  272.      pop   ds
  273.      pop   di
  274.      pop   si
  275. @@Done:
  276.      pop   bp
  277.      ret
  278. _x_define_mouse_cursor endp
  279.  
  280.  
  281. ;----------------------------------------------------------------------
  282. ; x_show_mouse - Shows a previously hidden mouse cursor
  283. ;
  284. ; C Prototype
  285. ;
  286. ;  void x_show_mouse()
  287. ;
  288. ; Written by Themie Gouthas
  289. ;----------------------------------------------------------------------
  290. _x_show_mouse proc
  291.      push  bp
  292.      mov   bp,sp
  293.      cmp   [_MouseInstalled],FALSE  ; Make sure our handler is installed
  294.      je    @@Done
  295.      cmp   [_MouseHidden],FALSE     ; If not hidden then exit
  296.      je    @@Done
  297.      push  si
  298.      push  di
  299.  
  300.  
  301. @@WaitEndOfHandler:               ; Make sure handler not currently active
  302.      mov   cl,[inhandler]
  303.      or    cl,cl
  304.      jnz   @@WaitEndOfHandler
  305.  
  306.  
  307.      mov   si,[_VisiblePageOffs]  ; Save mouse background and pos details
  308.      mov   ax,[_MouseY]
  309.      mov   bx,[_MouseX]
  310.      mov   [OldScrnOffs],si
  311.      mov   [OldY],ax
  312.      mov   [OldX],bx
  313.      call  getbg
  314.  
  315.      push [_VisiblePageOffs]      ; Draw cursor
  316.      push [_ScrnLogicalHeight]
  317.      xor  ax,ax
  318.      push ax
  319.      push [OldY]
  320.      push [OldX]
  321.      call _x_put_cursor
  322.      add  sp,10
  323.  
  324.      mov   [_MouseHidden],FALSE   ; Indicate mouse cursor no longer hidden
  325.  
  326.      pop  di
  327.      pop  si
  328. @@Done:
  329.      pop   bp
  330.      ret
  331. _x_show_mouse endp
  332.  
  333.  
  334. ;----------------------------------------------------------------------
  335. ; x_hide_mouse - Hides a previously visible mouse cursor
  336. ;
  337. ; C Prototype
  338. ;
  339. ;  void x_hide_mouse()
  340. ;
  341. ; Written by Themie Gouthas
  342. ;----------------------------------------------------------------------
  343. _x_hide_mouse proc
  344.      push  bp
  345.      mov   bp,sp
  346.  
  347.      cmp   [_MouseInstalled],FALSE   ; Make sure our handler is installed
  348.      je    @@Done
  349.      cmp   [_MouseHidden],FALSE      ; If cursor is already hidden exit
  350.      jne   @@Done
  351.      push  si
  352.      push  di
  353.  
  354. @@WaitEndOfHandler:            ; Make sure handler not currently active
  355.      mov   cl,[inhandler]
  356.      or    cl,cl
  357.      jnz   @@WaitEndOfHandler
  358.  
  359.      mov   [_MouseHidden],TRUE       ; Delete mouse cursor
  360.      mov   di,[OldScrnOffs]
  361.      mov   ax,[OldY]
  362.      mov   bx,[OldX]
  363.      call  restorebg
  364.      pop   di
  365.      pop   si
  366. @@Done:
  367.      pop   bp
  368.      ret
  369. _x_hide_mouse endp
  370.  
  371.  
  372. ;----------------------------------------------------------------------
  373. ; x_remove_mouse - removes mouse handler
  374. ;
  375. ; C Prototype
  376. ;
  377. ;  void x_remove_mouse()
  378. ;
  379. ; NOTE: This function MUST be called before quitting the program if
  380. ;       a mouse handler has been installed
  381. ;
  382. ; Written by Themie Gouthas
  383. ;----------------------------------------------------------------------
  384. _x_mouse_remove proc
  385.     push  bp
  386.     mov   bp,sp
  387.     cmp   [_MouseInstalled],FALSE  ; Check whether we have installed
  388.     je    @@Done                   ;  our mouse handler
  389.     call  _x_hide_mouse
  390.     mov   ax,12                    ; FUNC 12: Install event handler
  391.     xor   cx,cx                    ; Disable all events
  392.     int   33h
  393.     mov   [_MouseInstalled],FALSE
  394. @@Done:
  395.     pop   bp
  396.     ret
  397. _x_mouse_remove endp
  398.  
  399.  
  400. ;----------------------------------------------------------------------
  401. ; x_position_mouse - Positions the mouse cursor at the specified location
  402. ;
  403. ; C Prototype
  404. ;
  405. ;  void x_position_mouse(int x, int y)
  406. ;
  407. ;
  408. ; Written by Themie Gouthas
  409. ;----------------------------------------------------------------------
  410. _x_position_mouse proc
  411. ARG  X:word,Y:word
  412.      push  bp
  413.      mov   ax,4
  414.      mov   cx,X
  415.      shl   cx,1
  416.      mov   dx,Y
  417.      int   33h
  418.      pop   bp
  419.      ret
  420. _x_position_mouse endp
  421.  
  422. ;----------------------------------------------------------------------
  423. ; x_update_mouse - Forces the mouse position to be updated and cursor
  424. ;                  to be redrawn.
  425. ;
  426. ; C Prototype
  427. ;
  428. ;  void x_update_mouse()
  429. ;
  430. ; Note this function is useful when you have set "MouseFrozen" to true.
  431. ; Allows the cursor position to be updated manually rather than
  432. ; automatically by the installed handler.
  433. ;
  434. ;
  435. ; Written by Themie Gouthas
  436. ;----------------------------------------------------------------------
  437. _x_update_mouse proc
  438.      push  bp
  439.      mov   bp,sp
  440.      cmp   [_MouseInstalled],FALSE   ; Make sure our handler is installed
  441.      je    @@Done
  442.      cmp   [_MouseHidden],FALSE      ; If cursor is already hidden exit
  443.      jne   @@Done
  444.      push  si
  445.      push  di
  446.      mov   ax,03h                 ; FUNC 3: get cursor pos / button status
  447.      int   33h                    ; Update position variables first
  448.      shr   cx,1
  449.      mov   [_MouseX],cx
  450.      mov   [_MouseY],dx
  451.      mov   [_MouseButtonStatus],bx    ; Update button status
  452.  
  453.      mov   di,[OldScrnOffs]           ; Delete cursor (restore old background)
  454.      mov   ax,[OldY]
  455.      mov   bx,[OldX]
  456.      call  restorebg
  457.  
  458.      mov   si,[_VisiblePageOffs]      ; Save cursor background
  459.      mov   ax,[_MouseY]
  460.      mov   bx,[_MouseX]
  461.      mov   [OldScrnOffs],si
  462.      mov   [OldY],ax
  463.      mov   [OldX],bx
  464.      call  getbg
  465.  
  466.      push  [_VisiblePageOffs]         ; Draw the cursor
  467.      mov   ax,[_ScrnLogicalHeight]
  468.      push  ax
  469.      mov   ax,0
  470.      push  ax
  471.      push  [OldY]
  472.      push  [OldX]
  473.      call  _x_put_cursor
  474.      add   sp,10
  475.  
  476.      pop   di
  477.      pop   si
  478. @@Done:
  479.      pop   bp
  480.      ret
  481. _x_update_mouse endp
  482.  
  483.  
  484. ;----------------------------------------------------------------------
  485. ; x_put_cursor - Draws the mouse cursor
  486. ;
  487. ; C Prototype
  488. ;
  489. ; void x_put_cursor(int X, int Y, int TopClip, int BottomClip, WORD ScrnOffs)
  490. ;
  491. ;
  492. ; Written by Themie Gouthas
  493. ;----------------------------------------------------------------------
  494. ALIGN 2
  495. _x_put_cursor  proc
  496. ARG X:word,Y:word,TopClip,BottomClip,ScrnOffs
  497. LOCAL Height,TopRow,NextLineIncr:word=LocalStk
  498.     push  bp
  499.         mov   bp,sp
  500.     sub   sp,LocalStk                 ; Create space for local variables
  501.         push  si
  502.     push  di
  503.     push  ds
  504.     mov   ax,@data
  505.     mov   ds,ax
  506.     cld
  507.  
  508.     mov   ax,14                   ; Get image height and save in AX
  509.     mov   bx,Y
  510.     ; cx = top Row
  511.  
  512.     ;;;;; CLIP PROCESSING FOR TOP CLIP BORDER ;;;;;;;;;;;;;;;;;;;;;
  513.  
  514.     mov   dx,[TopClip]            ; Compare u.l. Y coord with Top
  515.     sub   dx,bx                   ; clipping border
  516.     jle   @@NotTopClip            ; jump if  not clipped from above
  517.     cmp   dx,ax
  518.     jnl   @@NotVisible            ; jump if  is completely obscured
  519.     mov   cx,dx
  520.     sub   ax,dx
  521.     add   bx,dx
  522.     jmp   short @@VertClipDone
  523.  
  524.     ;;;; EXIT FOR COMPLETELY OBSCURED  ;;;;;;;;;;;;;;;;;;;;;;
  525.  
  526. @@NotVisible:
  527.     pop   ds
  528.     pop   di                          ; restore registers
  529.     pop   si
  530.     mov   sp,bp                       ; dealloc local variables
  531.     pop   bp
  532.     ret
  533.  
  534.     ;;;;; CLIP PROCESSING FOR BOTTOM CLIP BORDER ;;;;;;;;;;;;;;;;;;;
  535.  
  536. @@NotTopClip:
  537.     mov   dx,[_BottomClip]
  538.     sub   dx,bx
  539.     js    @@NotVisible
  540.     mov   cx,0
  541.     cmp   dx,ax
  542.     jg    @@VertClipDone
  543.     inc   dx
  544.     mov   ax,dx
  545.  
  546. @@VertClipDone:
  547.  
  548.     mov   [Height],ax
  549.     mov   [TopRow],cx
  550.  
  551.         mov   ax,SCREEN_SEG               ; Point es to VGA segment
  552.     mov   es,ax
  553.  
  554.     mov   ax,bx
  555.     mov   cx,[_ScrnLogicalByteWidth]  ; Find required screen address
  556.     mul   cx
  557.     mov   di,ax
  558.  
  559.     sub   cx,3                        ; Distance to next screen row
  560.     mov   [NextLineIncr],cx
  561.  
  562.  
  563.     mov   cx,[X]
  564.     mov   bx,cx
  565.     shr   cx,2
  566.     add   di,cx
  567.     and   bx,3
  568.     add   di,[ScrnOffs]
  569.  
  570.     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  571.  
  572.  
  573.     mov   ax,42
  574.     mul   bx
  575.     mov   si,offset MouseMask
  576.     add   si,ax
  577.  
  578.     mov   ax,3                        ; Increment DS:BX and DS:SI to
  579.     mul   [TopRow]                    ;  been clipped by the top border
  580.     add   si,ax                       ; by the L.H.S border
  581.  
  582.     mov   dx,SC_INDEX                 ; Point SC register to map mask
  583.     mov   al,MAP_MASK                 ; in preperation for masking data
  584.     out   dx,al
  585.     inc   dx                          ; Point dx to SC data register
  586.     mov   ah,byte ptr [Height]        ; AH = Scanline loop counter
  587.     mov   bl,[_MouseColor]
  588. @@RowLoop:
  589.     mov   cx,3                        ; Width in bytes across
  590. @@ColLoop:
  591.     lodsb                             ; load plane mask and set MAP MASK
  592.     out   dx,al
  593.     mov   es:[di],bl                  ; store color to specified planes
  594.     inc   di
  595.     loop  @@ColLoop
  596.  
  597.     add   di,[NextLineIncr]
  598.     dec   ah
  599.     jnz   @@RowLoop
  600.  
  601.     pop   ds
  602.         pop   di                          ; restore registers
  603.         pop   si
  604.         mov   sp,bp                       ; dealloc local variables
  605.         pop   bp
  606.         ret
  607. _x_put_cursor  endp
  608.  
  609.  
  610. ;----------------------------------------------------------------------
  611. ; getbg - saves cursor background
  612. ;
  613. ; C Prototype
  614. ;
  615. ; local function using register parameters
  616. ;
  617. ; si = screen offset
  618. ; ax  = y
  619. ; bx  = x
  620. ;
  621. ; Written by Themie Gouthas
  622. ;----------------------------------------------------------------------
  623. ALIGN 2
  624. getbg  proc near
  625.  
  626.     push  bp
  627.     mov   bp,sp
  628.     push  ds
  629.     cld
  630.  
  631.     mov   cx,[_ScrnLogicalByteWidth]  ;  by mult. dest Y coord by Screen
  632.     mul   cx                          ;  width then adding screen offset
  633.     add   si,ax                       ; Add Dest Screen Row to di
  634.     sub   cx,3
  635.     shr   bx,2
  636.     add   si,bx
  637.     mov   di,BGSaveOffs
  638.         mov   ax,SCREEN_SEG               ; Point es to VGA segment
  639.     mov   es,ax
  640.     mov   ds,ax
  641.  
  642.     mov   dx,GC_INDEX                 ; Set bit mask for all bits from
  643.     mov   ax,BIT_MASK                 ; VGA latches and none from CPU
  644.     out   dx,ax
  645.  
  646.     mov   dx,SC_INDEX                 ; Point SC register to map mask
  647.     mov   al,MAP_MASK           ; in preperation for masking data
  648.         out   dx,al
  649.     inc   dx
  650.     mov   al,0fh
  651.     out   dx,al
  652.  
  653.     mov   bx,cx
  654.     mov   cx,14
  655. @@Loop:
  656.     movsb
  657.     movsb
  658.     movsb
  659.     add si,bx
  660.     loop @@Loop
  661.  
  662. mov     dx,GC_INDEX+1 ;restore the bit mask to its default,
  663.         mov     al,0ffh       ; which selects all bits from the CPU
  664.         out     dx,al         ; and none from the latches (the GC
  665.                               ; Index still points to Bit Mask)
  666.  
  667.     pop   ds
  668.         mov   sp,bp                       ; dealloc local variables
  669.         pop   bp
  670.         ret
  671. getbg  endp
  672.  
  673. ;----------------------------------------------------------------------
  674. ; restorebg - restores cursor background
  675. ;
  676. ; C Prototype
  677. ;
  678. ; local function using register parameters
  679. ;
  680. ; di = screen offset
  681. ; ax  = y
  682. ; bx  = x
  683. ;
  684. ; Written by Themie Gouthas
  685. ;----------------------------------------------------------------------
  686. ALIGN 2
  687. restorebg  proc near
  688. ;di = scrn offs
  689. ;ax  = y
  690. ;bx  = x
  691.     push  bp
  692.     mov   bp,sp
  693.     push  ds
  694.     cld
  695.  
  696.     mov   cx,[_ScrnLogicalByteWidth]  ;  by mult. dest Y coord by Screen
  697.     mul   cx                          ;  width then adding screen offset
  698.     add   di,ax                       ; Add Dest Screen Row to di
  699.     sub   cx,3
  700.     shr   bx,2
  701.     add   di,bx
  702.     mov   si,BGSaveOffs
  703.         mov   ax,SCREEN_SEG               ; Point es to VGA segment
  704.     mov   es,ax
  705.     mov   ds,ax
  706.  
  707.     mov   dx,GC_INDEX                 ; Set bit mask for all bits from
  708.     mov   ax,BIT_MASK                 ; VGA latches and none from CPU
  709.     out   dx,ax
  710.  
  711.     mov   dx,SC_INDEX                 ; Point SC register to map mask
  712.     mov   al,MAP_MASK                 ; in preperation for masking data
  713.     out   dx,al
  714.     inc   dx
  715.     mov   al,0fh
  716.     out   dx,al
  717.  
  718.     mov   bx,cx
  719.     mov   cx,14
  720. @@Loop:
  721.     movsb
  722.     movsb
  723.     movsb
  724.     add di,bx
  725.     loop @@Loop
  726.  
  727.     mov  dx,GC_INDEX+1 ;restore the bit mask to its default,
  728.     mov  al,0ffh       ; which selects all bits from the CPU
  729.     out  dx,al         ; and none from the latches (the GC
  730.                ; Index still points to Bit Mask)
  731.     pop   ds
  732.         pop   bp
  733.         ret
  734. restorebg  endp
  735.  
  736.  
  737. ;********************** The Mouse event handler *************************
  738.  
  739. ALIGN 2
  740. mouse_handler proc far
  741. LOCAL poschange:word=StkSize
  742.    push  bp
  743.    mov   bp,sp
  744.    sub   sp,StkSize
  745.    push  ds
  746.    push  si
  747.    push  di
  748.    mov   ax,@data                   ; Make sure DS points to data segment
  749.    mov   ds,ax
  750.    mov   [inhandler],1
  751.    mov   [_MouseButtonStatus],bx    ; Update button status
  752.    test  cx,1                       ; Is this a motion event ?
  753.    jnz   @@Done                     ; Yes Jump
  754.  
  755.    shr  cx,1                        ; convert X coord to pixel coords
  756.    mov  [_MouseX],cx                ; save mouse position
  757.    mov  [_MouseY],dx
  758.  
  759.    cmp  [_MouseHidden],TRUE         ; If mouse hidden dont bother drawing
  760.    je   @@Done
  761.  
  762.    cmp  [_MouseFrozen],TRUE         ; If mouse hidden dont bother drawing
  763.    je   @@Done
  764.  
  765.    WaitVsyncStart
  766.  
  767.    mov di,[OldScrnOffs]             ; Delete cursor (restore old background)
  768.    mov ax,[OldY]
  769.    mov bx,[OldX]
  770.    call restorebg
  771.  
  772.    mov si,[_VisiblePageOffs]        ; Save cursor background
  773.    mov ax,[_MouseY]
  774.    mov bx,[_MouseX]
  775.    mov [OldScrnOffs],si
  776.    mov [OldY],ax
  777.    mov [OldX],bx
  778.    call getbg
  779.  
  780.    push [_VisiblePageOffs]          ; Draw the cursor
  781.    mov  ax,[_ScrnPhysicalHeight]
  782.    push ax
  783.    mov  ax,0
  784.    push ax
  785.    push [OldY]
  786.    push [OldX]
  787.    call _x_put_cursor
  788.    add  sp,10
  789.  
  790. @@Done:
  791.    mov  [inhandler],0
  792.    pop  di
  793.    pop  si
  794.    pop  ds
  795.    mov  sp,bp
  796.    pop  bp
  797.    ret
  798. mouse_handler endp
  799.  
  800.  
  801. end